package org.wak.gui.sci
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;

	/**
	 * Iconic mouse pointer for SCI. 
	 * @author mindscout
	 * 
	 */	
	public class SciCursor extends Sprite
	{
		private var mWhiteDot:Shape = null ; 
		private var mDefaultIcon:DisplayObject = null ;
		
		private var mCurrentIcon:DisplayObject = null ;
		
	    
		/**
		 * Constructor. 
		 * @param pDefaultIcon DisplayObject to display as default mouse icon.
		 * 
		 */		
		public function SciCursor(pDefaultIcon:DisplayObject)
		{
			super();
			mDefaultIcon = pDefaultIcon ;
			
			this.addChild(mDefaultIcon);
			mCurrentIcon = mDefaultIcon ;
			
			mWhiteDot = new Shape();
			mWhiteDot.graphics.beginFill(0xFFFFFF);
			mWhiteDot.graphics.drawRect(-1,-1,3,3);
			mWhiteDot.graphics.endFill();
			mWhiteDot.graphics.lineStyle(1,0x000000);
			mWhiteDot.graphics.drawRect(-1,-1,3,3);
			mWhiteDot.graphics.endFill();
			
			
			//this.addEventListener(Event.ADDED_TO_STAGE, OnAddedToStage );
			
		}
		
		/**
		 * Set a DisplayObject as mouse icon. 
		 * @param pIcon icon to attach to the mouse pointer.
		 * @param pMarkActionPoint if true, the action spot is marked with an outlined white dot.
		 * 
		 */		
		public function SetActiveIcon(pIcon:DisplayObject, pMarkActionPoint:Boolean = false ):void
		{
			if( (pIcon == null) || pIcon == mCurrentIcon )
				return ;
				
			if( this.contains( mCurrentIcon ) )
				this.removeChild( mCurrentIcon );
				
			mCurrentIcon = pIcon ;
			this.addChild( mCurrentIcon );
			
			if(pMarkActionPoint)
			{
				this.addChild(mWhiteDot);
			}
			
		}
		
		/**
		 * True if the current mouse icon is the set as default. 
		 * @return 
		 * 
		 */		
		public function get isDefault():Boolean
		{
			return (mCurrentIcon == mDefaultIcon) ;
		}
		
		/**
		 * Set the current mouse icon to default. 
		 * 
		 */		
		public function SetDefault():void
		{
			if( this.contains( mCurrentIcon ) )
				this.removeChild( mCurrentIcon );
				
			mCurrentIcon = mDefaultIcon ;
			this.addChild( mCurrentIcon );
			
			if(this.contains(mWhiteDot))
				this.removeChild(mWhiteDot);
		}
		
		
/* 		
		private function OnAddedToStage(event:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, OnAddedToStage );
			this.addEventListener(Event.ENTER_FRAME,Update);
			
			this.addEventListener(Event.REMOVED_FROM_STAGE, OnRemovedFromStage );
		}
		
		private function OnRemovedFromStage(event:Event):void
		{
			this.removeEventListener(Event.REMOVED_FROM_STAGE, OnRemovedFromStage );
			this.removeEventListener(Event.ENTER_FRAME,Update);
			
			this.addEventListener(Event.ADDED_TO_STAGE, OnAddedToStage );
			
		}
		private function Update(event:Event):void
		{
			if(mCurrentIcon != null)
			{
				mCurrentIcon.x = this.x ;
				mCurrentIcon.y = this.y ;
			}
		}
	 */	
		
	}
}